//
//  ViewController.swift
//  通知的使用
//
//  Created by YYY on 2017/9/4.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textView1: UITextView!
    
    @IBOutlet weak var textView2: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        /*
         监听对象
         监听方法
         监听的通知名字
         发送通知的对象，如果是nil，监听所有对象
         */
        //注册监听者
        NotificationCenter.default.addObserver(self, selector: #selector(observeTextChange), name: NSNotification.Name.UITextViewTextDidChange, object: textView1)
        // Do any additional setup after loading the view, typically from a nib.
    }

    @objc private func observeTextChange(notification: NSNotification)
    {
        print(notification)
        
        //发送通知
        NotificationCenter.default.post(name: Notification.Name.UITextViewTextDidChange, object: nil, userInfo: nil)
    }
    
    //移除通知
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

